package com.nononsenseapps.feeder.pad.ui.reader.sample

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.fragment.app.*
import com.lxj.xpopup.interfaces.XPopupCallback
import timber.log.Timber


class ReaderFragmentDialog : DialogFragment() {

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val wrapper = FrameLayout(activity)
        wrapper.id = Companion.CONTAINER_ID
        childFragmentManager.commitNow {
            replace<ReaderFragment>(Companion.CONTAINER_ID, Companion.TAG,Bundle().apply{
                putBoolean(DIALOG_MODEL_FLAG,true)
            })
        }
        childFragmentManager.findFragmentByTag(Companion.TAG)?.let {
            Timber.d("findFragment ReaderFragment...")
            if(it is ReaderFragment)
                it.xPopupCallback=object:XPopupCallback{
                    override fun onBackPressed(): Boolean =false

                    override fun onDismiss() {
                       dialog?.show()
                    }

                    override fun beforeShow() {
                        dialog?.hide()
                    }

                    override fun onCreated() {}

                    override fun onShow() {}
                }
        }
        return wrapper
    }

    companion object {
        private const val TAG:String="read_fragment"
        private const val CONTAINER_ID: Int = 0x2222
    }

}